package com.asj.vivo.lock.service;

import static com.asj.enums.DeviceIdentifierDictEnums.json_key_deviceCode;

import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

import com.asj.MainActivity;

import lombok.Getter;

/**
 * 集中仓库服务，通过其赋值获取值
 * */
@Getter
public class WarehouseService extends Service {

    //主活动，许多地方都需要靠其进行活动
    public static MainActivity mainActivity;
    private static PrefsHelper prefsHelper;

    @Override
    public void onCreate() {
        super.onCreate();
        prefsHelper = new PrefsHelper(this);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // 这里可以处理服务启动的逻辑
        // 例如，根据intent中的数据更新SharedPreferences中的值
        if (intent != null) {
            String value = intent.getStringExtra(json_key_deviceCode.getValue());
            if (value != null) {
                prefsHelper.setStringValue(value);
            }
        }
        // 将服务设置为前台服务
        startForeground(1, new Notification());
        return START_STICKY;
    }

    private final IBinder binder = new LocalBinder();

    public class LocalBinder extends Binder {
        public WarehouseService getService() {
            return WarehouseService.this;
        }
    }

    public PrefsHelper getPrefsHelper() {
        return prefsHelper;
    }

    @Override
    public IBinder onBind(Intent intent) {
        return binder;
    }
}
